<!--
 * @Author: HeAo
 * @Date: 2021-10-13 11:16:26
 * @LastEditTime: 2021-10-13 11:35:01
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day05\6-嵌套路由.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
  <style>
    header {
      height: 50px;
      /* border: 1px solid blue; */
      /* margin: 10px; */
      background-color: cadetblue;
      color: white;
    }

    main {
      /* height: calc(100% - 150px); */
      height: 700px;
      display: flex;
    }

    .left {
      width: 150px;
      height: 100%;
      border: 3px solid green;
      margin: 10px;
    }

    .right {
      width: calc(100% - 150px);
      height: 100%;
      border: 3px solid orange;
      margin: 10px;
    }
  </style>
</head>

<body>
  <div id="app">
    <header>
      我是网站头部
    </header>
    <main>
      <div class="left">
        <!-- 路由跳转链接 -->
        <div>
          <router-link to="/user">用户管理</router-link>
        </div>
        <div>
          <router-link to="/student">学生管理</router-link>
        </div>
        <div>
          <router-link to="/clazz">班级管理</router-link>
        </div>
      </div>
      <div class="right">
        <!-- 路由对应组件加载的窗口 -->
        <router-view></router-view>
      </div>
    </main>
  </div>
  <script>
    // 1.声明组件
    let com1 = {
      data() {
        return {}
      },
      template: `
        <div>
          用户管理
        </div>
      `
    }
    let com2 = {
      data() {
        return {}
      },
      template: `
        <div>
          学生管理
          <div>
            <router-link to="/student/grade">成绩管理</router-link>
            <router-link to="/student/register">学籍管理</router-link>
          </div>
          <router-view></router-view>
        </div>
      `
    }
    let com3 = {
      data() {
        return {}
      },
      template: `
        <div>
          班级管理
        </div>
      `
    }
    let comGrade = {
      data() {
        return {}
      },
      template: `
        <div>
          成绩管理
        </div>
      `
    }
    let comRegister = {
      data() {
        return {}
      },
      template: `
        <div>
          学籍管理
        </div>
      `
    }
    // 2.定义路由
    let router = new VueRouter({
      routes: [
        {
          path: '/user',   // 动态路由，冒号开头的字段是动态参数
          component: com1,// 路径对应加载的组件
          name: 'user'
        },
        {
          path: '/student',
          component: com2,
          children: [
            { path: 'grade', component: comGrade },
            { path: 'register', component: comRegister },
          ]
        },
        { path: '/clazz', component: com3 },
      ]
    })

    // 3.注册路由、组件
    let vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      // components: {
      //   myCom1: com1,
      //   myCom2: com2,
      //   myCom3: com3,
      // },
      router
    })
  </script>
</body>

</html>